import 'package:flutter/material.dart';
import 'package:dio/dio.dart';

void getHttp() async{
  try {
    Response response;
    response = await Dio().get('path');
    return print(response);
    
  } catch (e) {
    return print(e);
  }
}


Future getValue (String typeText) async {
  try {
    Response response;
    var data = {"name" : typeText };
    response = await Dio().get(
      'https://www.easy-mock.com/mock/5c60131a4bed3a6342711498/baixing/dabaojian',
       queryParameters: data
       );
       print(response);
    return response.data;
  } catch (e) {
    print(e);
  }
}
class Index extends StatefulWidget {
  Index({Key key}) : super(key: key);

  _Index createState() => _Index();
}

class _Index extends State<Index> {
  TextEditingController typeContoller = TextEditingController();
  String showDesc = '欢迎您来到这里，';

  void _selectAction () {
  if (typeContoller.text.toString() == '') {
    showDialog(
      context: context,
      builder: (context) => AlertDialog(
        title: Text('类型不能为空'),
      )
    );
    return;
  }

  getValue(typeContoller.text.toString()).then((value) {
    setState(() {
     showDesc = value['data']['name']; 
    });
  });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        padding: EdgeInsets.all(10),
        child: Column(
          children: <Widget>[
            TextField(
              controller: typeContoller,
              decoration: InputDecoration(
                contentPadding: EdgeInsets.all(10),
                labelText: '类型',
                helperText: '请输入你喜欢的类型'
              ),
              autofocus: false,
            ),

            RaisedButton(
              onPressed: _selectAction,
              child: Text('选择完毕'),
            ),
            Text(showDesc, overflow: TextOverflow.ellipsis, maxLines: 2,)
          ],
        ),
      ),
    );
  }
}